#region Imported Namespaces
using System;
using System.Data;
using System.Data.SqlClient;

using BO = PHSRAG.Insight21.BusinessObjects;
using Utility = PHSRAG.Utility;
using ICachePolicy = PHSRAG.Insight21.Policy.ICachePolicy;
using GenerateKey = PHSRAG.Insight21.BusinessObjects.ModuleKey;
#endregion

namespace PHSRAG.Insight21.Agreements
{
	#region Class RevenueBreakdown
	/// <summary>
	/// Summary description for RevenueBreakdown.
	/// </summary>
	public class RevenueBreakdown : BO.BusinessObject
	{
		#region Constants
		private static string RevenueBreakdownKey			= GenerateKey.MakeKey("RevenueBreakdown_8021F7C5-E6F6-4fac-AB4C-4291DFDA1E3B",GenerateKey.Agreement);
		private const string RevenueBreakdownDataTableName	= "RevenueBreakdown";
		#endregion

		#region Constructor
		/// <summary>
		/// Initialize the state of this object
		/// </summary>
		public RevenueBreakdown(ICachePolicy cachePolicy) : base(cachePolicy)
		{
			DataContainer = new DataSet();
		}
		#endregion

		#region Properties
		/// <summary>
		/// Get TransactionID for transaction identification (FinJournalFctId) from the internal DataContainer
		/// </summary>
		/// <remarks>
		/// The Transaction ID will not be null when returned from the database.
		/// </remarks>
		public int TransactionID
		{
			get
			{
				return (int)DataContainer.Tables[RevenueBreakdownDataTableName].Rows[0]["TransactionID"];
			}
		}

		/// <summary>
		/// Get Fund Number property from the internal DataContainer
		/// </summary>
		/// <remarks>
		/// The FundNumber will not be null when returned from the database.
		/// </remarks>
		public string FundNumber
		{
			get
			{
				return (string)DataContainer.Tables[RevenueBreakdownDataTableName].Rows[0]["FundNumber"];
			}
		}

		/// <summary>
		/// Get Project Title property from the internal DataContainer
		/// </summary>
		/// <remarks>
		/// The ProjectTitle will not be null when returned from the database.
		/// </remarks>
		public string ProjectTitle
		{
			get
			{
				object o = DataContainer.Tables[RevenueBreakdownDataTableName].Rows[0]["ProjectTitle"];
				return (o == DBNull.Value) ? "" : (string)o;
			}
		}

		/// <summary>
		/// Get Sponsor Name property from the internal DataContainer
		/// </summary>
		/// <remarks>
		/// The SponsorName will not be null when returned from the database.
		/// </remarks>
		public string SponsorName
		{
			get
			{
				return (string)DataContainer.Tables[RevenueBreakdownDataTableName].Rows[0]["SponsorName"];
			}
		}

		/// <summary>
		/// Get PI Name property from the internal DataContainer
		/// </summary>
		/// <remarks>
		/// The PIName will not be null when returned from the database.
		/// </remarks>
		public string PIName
		{
			get
			{
				return (string)DataContainer.Tables[RevenueBreakdownDataTableName].Rows[0]["PIName"];
			}
		}

		/// <summary>
		/// Get Account Number property from the internal DataContainer
		/// </summary>
		/// <remarks>
		/// The AccountNumber will not be null when returned from the database.
		/// </remarks>
		public string AccountNumber
		{
			get
			{
				return (string)DataContainer.Tables[RevenueBreakdownDataTableName].Rows[0]["AccountNumber"];
			}
		}

		/// <summary>
		/// Get Account Name property from the internal DataContainer
		/// </summary>
		/// <remarks>
		/// The AccountName may be null when returned from the database.
		/// </remarks>
		public string AccountName
		{
			get
			{
				object o = DataContainer.Tables[RevenueBreakdownDataTableName].Rows[0]["AccountName"];
				return (o == DBNull.Value) ? "" : (string)o;
			}
		}

		/// <summary>
		/// Get Revenue Amount property from the internal DataContainer
		/// </summary>
		/// <remarks>
		/// The Amount may be null when returned from the database.
		/// </remarks>
		public decimal Amount
		{
			get
			{
				object o = DataContainer.Tables[RevenueBreakdownDataTableName].Rows[0]["Amount"];
				return (o == DBNull.Value) ? 0 : (decimal)o;
			}
		}

		/// <summary>
		/// Get Revenue Date property from the internal DataContainer
		/// </summary>
		/// <remarks>
		/// The DatePosted may be null when returned from the database.
		/// </remarks>
		public string DatePosted
		{
			get
			{
				object o = DataContainer.Tables[RevenueBreakdownDataTableName].Rows[0]["DatePosted"];
				return (o == DBNull.Value) ? "" : ((DateTime)o).ToString("MM/dd/yy");
			}
		}

        public string ToolTipForFund
        {
            get
            {
                return (string)DataContainer.Tables[RevenueBreakdownDataTableName].Rows[0]["ToolTipForFund"];
               
            }
        }

        public string EntryDescription
        {
            get
            {
                return (string)DataContainer.Tables[RevenueBreakdownDataTableName].Rows[0]["EntryDescription"];
           
            }
        }
		#endregion

		#region Business Object Methods
		/// <summary>
		/// Cache this object according to the cache policy
		/// </summary>
		public override void Cache()
		{
			CachePolicy.Cache(RevenueBreakdownKey, this);
		}

		/// <summary>
		/// Load the DataSet with RevenueBreakdown data by executing the stored procedure
		/// "GetRevenueBreakdown".  Throws system exception if an error is encountered 
		/// during the load process.
		/// </summary>
		/// <remarks>
		/// This method loads a single row in the DataContainer with the entire information for a single revenue transaction,
		/// specified by a FinJournalTransaction_Src table ID number.
		/// </remarks>
		/// <param name="connectionString">Sql Connection string info</param>
		/// <param name="args">Additional user or page defined parameters</param>
		public override void Load(string connectionString, params object[] args)
		{
			// Check the number of arguments
			if(args.Length != 3)
				throw new Exception("RevenueBreakdown load requires SessionID, DomainUserId and FinJournalFctId");

			try
			{
				DataContainer.Reset();

				Utility.DataAccess.LoadDataSet(DataContainer, RevenueBreakdownDataTableName, connectionString, "GetRevenueBreakdown",
					Utility.DataAccess.BuildSqlParameterArray(
						"@sessionId",					SqlDbType.VarChar,	(string)args[0],
						"@domainUserID",				SqlDbType.Int,		(int)args[1],
						"@fromDate",					SqlDbType.DateTime,	DBNull.Value,
						"@toDate",						SqlDbType.DateTime, DBNull.Value,
						"@finJournalTransactionSrcId",	SqlDbType.Int,		(int)args[2]));
			}
			catch(Exception e)
			{
				Utility.ExceptionReport.WriteToEventLog ("RevenueBreakdown Load", e, true, Utility.ExceptionReport.ReportType.Error);
			}
		}
		
		/// <summary>
		/// Uncache this object according to the cache policy
		/// </summary>
		public override void UnCache()
		{
			CachePolicy.UnCache(RevenueBreakdownKey);
		}
		#endregion
	}
	#endregion
}

// --- EOF ---
